#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "sqlite3.h"
#define STRLEN 500

int main(int argc, char *argv[])
{
    sqlite3 *db = NULL;
    char sql[STRLEN];
    char *zErrMsg;
    int rc = sqlite3_open("test.db", &db);
    if(rc != SQLITE_OK)
    {
        printf("Can't open database: %s\n", sqlite3_errmsg(db));
        sqlite3_close(db);
        return 1;
    }
    printf("You have opend a sqlite3 file named test.db successfully!\n");
    strcpy(sql, "CREATE TABLE IF NOT EXISTS DbLog(Id INTEGER PRIMARY KEY AUTOINCREMENT, description NVARCHAR(500));");
    rc = sqlite3_exec(db, sql, NULL, NULL, &zErrMsg);
    if(rc != SQLITE_OK)
    {
        printf("Create table error. %s\n", zErrMsg);
    }
    strcpy(sql, "insert into DbLog(description) values('You have create a database named DbLog.')");
    sqlite3_exec(db, sql, NULL, NULL, &zErrMsg);
    //memset(sql, '\0', STRLEN);
    strcpy(sql, "insert into DbLog(description) values('You have insert some records into database.')");
    sqlite3_exec(db, sql, NULL, NULL, &zErrMsg);
    sqlite3_close(db);

    return 0;
}
